
#include <allegro.h>
struct Perso {
	BITMAP * img_right[NB_IMAGES];
	BITMAP * img_left[NB_IMAGES];
	int x, y;
	int direction; 
};
typedef struct Perso Perso;

struct Scroller 
{
int x; 
int y; 
	
	 
} ;
typedef struct Scroller Scroller;

int main() 
{
char chemin_background[]="../images/map_elfe.bmp";
char chemin_background1[]="../images/backgroundC.bmp"
char chemin_background2[]="../images/Background2.bmp";
char chemin_background3[]="../images/Background3.bmp";
BITMAP *Buffer;

BITMAP *Background;
BITMAP *Background1;
BITMAP *Background2;
BITMAP *Background3;
int continuer=1 ;	
int menu=0;  
Perso Perso;

Scroller scrol;  

allegro_init();
if (install_keyboard() == -1) {
allegro_message("Error! %s", allegro_error);
return -1;
}
set_color_depth(24);
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); 
allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
return 1;
}
scrol.x=0;
scrol.y=0;	
Perso.x=20; 
Perso.y=450; 
Perso.image1= load_bitmap("../images/jump_right.bmp",NULL);
Buffer = create_bitmap(800, 600);
Background = load_bitmap(chemin_background, NULL);
Background1 = load_bitmap(chemin_background1, NULL);
Background2 = load_bitmap(chemin_background2, NULL);
Background3 = load_bitmap(chemin_background3, NULL);


if ( Background == NULL)
 {
allegro_message("could not load images");
allegro_exit();
}








blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

blit(Background, Buffer, 0, 0, 0, 0, Background->w, Background->h);
draw_sprite(Buffer, Perso.image1,Perso.x,Perso.y);
blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
while(continuer!=0)
{
	

if(key[KEY_RIGHT]  &&  scrol.x> (-Background->w +800)  )
{
scrol.x-=1;
Buffer = create_bitmap(800, 600);	 
blit(Background, Buffer,  0, 0,scrol.x, scrol.y, Background->w, Background->h);	
draw_sprite(Buffer, Perso.image1,Perso.x,Perso.y);
blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);}	
if(scrol.x < -(1700))
{ clear(Buffer);
	scrol.x=0;
	
	menu=1;
}

while(menu==1 && key[KEY_RIGHT] && scrol.x> (-Background->w +800) )
{

	scrol.x-=1;
	blit(Background1, Buffer,  0,0, scrol.x,scrol.y, Background1->w, Background1->h);	
	draw_sprite(Buffer, Perso.image1,Perso.x,Perso.y);
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	if(scrol.x < -(1700))
{ clear(Buffer);
	scrol.x=0;
	menu=2;}	
	}
	while (menu==2 && key[KEY_RIGHT] && scrol.x> (-Background->w +800)   )
{
scrol.x-=1;
	blit(Background2, Buffer,  0,0, scrol.x,scrol.y, Background2->w, Background2->h);	
draw_sprite(Buffer, Perso.image1,Perso.x,Perso.y);
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		if(scrol.x < -(1700))
{ clear(Buffer);
	scrol.x=0;
	menu=3;}	
	}
		while (menu==3 && key[KEY_RIGHT] && scrol.x> (-Background->w +800)   )
{
scrol.x-=1;
	blit(Background3, Buffer,  0,0, scrol.x,scrol.y, Background3->w, Background3->h);	
draw_sprite(Buffer, Perso.image1,Perso.x,Perso.y);
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		if(scrol.x < -(1700))
{ clear(Buffer);
	scrol.x=0;
	menu=4;}	
	}
	}
destroy_bitmap(Background);
destroy_bitmap(Perso.image1);



 


return 0;}




